{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6d25b754",
   "metadata": {},
   "source": [
    "# Annotation Labels on Pie-Chart\n",
    " Annotation Labels on Pie-Chart specifies content of the annotations.\n",
    " \n",
    " 1. [Default presentation](#1.Default-presentation)\n",
    " \n",
    " 2. [Change default annotation](#2.-Change-default-annotation)\n",
    " \n",
    " 3. [Use colors of the flavor scheme](#3.-Use-colors-of-the-flavor-scheme)\n",
    " \n",
    " 4. [Annotations for Pie-Chart with explode parameter](#4.-Annotations-for-Pie-Chart-with-explode-parameter)\n",
    " \n",
    " 5. [Annotations on scatter pie plot](#5.-Annotations-on-scatter-pie-plot)\n",
    " \n",
    " 6. [Annotations for Pie-Chart with different sector's size](#6.-Annotations-for-Pie-Chart-with-different-sector's-size) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5f374090",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"dURHAo\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"library\">\n",
       "       if(!window.letsPlotCallQueue) {\n",
       "           window.letsPlotCallQueue = [];\n",
       "       }; \n",
       "       window.letsPlotCall = function(f) {\n",
       "           window.letsPlotCallQueue.push(f);\n",
       "       };\n",
       "       (function() {\n",
       "           var script = document.createElement(\"script\");\n",
       "           script.type = \"text/javascript\";\n",
       "           script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v3.2.0/js-package/distr/lets-plot.min.js\";\n",
       "           script.onload = function() {\n",
       "               window.letsPlotCall = function(f) {f();};\n",
       "               window.letsPlotCallQueue.forEach(function(f) {f();});\n",
       "               window.letsPlotCallQueue = [];\n",
       "               \n",
       "               \n",
       "           };\n",
       "           script.onerror = function(event) {\n",
       "               window.letsPlotCall = function(f) {};\n",
       "               window.letsPlotCallQueue = [];\n",
       "               var div = document.createElement(\"div\");\n",
       "               div.style.color = 'darkred';\n",
       "               div.textContent = 'Error loading Lets-Plot JS';\n",
       "               document.getElementById(\"dURHAo\").appendChild(div);\n",
       "           };\n",
       "           var e = document.getElementById(\"dURHAo\");\n",
       "           e.appendChild(script);\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "            <div id=\"kotlin_out_0\"></div>\n",
       "            <script type=\"text/javascript\">\n",
       "                            if(!window.kotlinQueues) {\n",
       "                window.kotlinQueues = {};\n",
       "            }\n",
       "            if(!window.kotlinQueues[\"DataFrame\"]) {\n",
       "                var resQueue = [];\n",
       "                window.kotlinQueues[\"DataFrame\"] = resQueue;\n",
       "                window[\"call_DataFrame\"] = function(f) {\n",
       "                    resQueue.push(f);\n",
       "                }\n",
       "            }\n",
       "            (function (){\n",
       "                var modifiers = [(function(script) {\n",
       "    script.src = \"https://cdn.jsdelivr.net/gh/Kotlin/dataframe@3db46ccccaa1291c0627307d64133317f545e6ae/core/src/main/resources/init.js\"\n",
       "    script.type = \"text/javascript\";\n",
       "})];\n",
       "                var e = document.getElementById(\"kotlin_out_0\");\n",
       "                modifiers.forEach(function (gen) {\n",
       "                    var script = document.createElement(\"script\");\n",
       "                    gen(script)\n",
       "                    script.addEventListener(\"load\", function() {\n",
       "                        window[\"call_DataFrame\"] = function(f) {f();};\n",
       "                        window.kotlinQueues[\"DataFrame\"].forEach(function(f) {f();});\n",
       "                        window.kotlinQueues[\"DataFrame\"] = [];\n",
       "                    }, false);\n",
       "                    script.addEventListener(\"error\", function() {\n",
       "                        window[\"call_DataFrame\"] = function(f) {};\n",
       "                        window.kotlinQueues[\"DataFrame\"] = [];\n",
       "                        var div = document.createElement(\"div\");\n",
       "                        div.style.color = 'darkred';\n",
       "                        div.textContent = 'Error loading resource DataFrame';\n",
       "                        document.getElementById(\"kotlin_out_0\").appendChild(div);\n",
       "                    }, false);\n",
       "                    \n",
       "                    e.appendChild(script);\n",
       "                });\n",
       "            })();\n",
       "            </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "                <style>\n",
       "                :root {\n",
       "    --background: #fff;\n",
       "    --background-odd: #f5f5f5;\n",
       "    --background-hover: #d9edfd;\n",
       "    --header-text-color: #474747;\n",
       "    --text-color: #848484;\n",
       "    --text-color-dark: #000;\n",
       "    --text-color-medium: #737373;\n",
       "    --text-color-pale: #b3b3b3;\n",
       "    --inner-border-color: #aaa;\n",
       "    --bold-border-color: #000;\n",
       "    --link-color: #296eaa;\n",
       "    --link-color-pale: #296eaa;\n",
       "    --link-hover: #1a466c;\n",
       "}\n",
       "\n",
       ":root[theme=\"dark\"], :root [data-jp-theme-light=\"false\"], .dataframe_dark{\n",
       "    --background: #303030;\n",
       "    --background-odd: #3c3c3c;\n",
       "    --background-hover: #464646;\n",
       "    --header-text-color: #dddddd;\n",
       "    --text-color: #b3b3b3;\n",
       "    --text-color-dark: #dddddd;\n",
       "    --text-color-medium: #b2b2b2;\n",
       "    --text-color-pale: #737373;\n",
       "    --inner-border-color: #707070;\n",
       "    --bold-border-color: #777777;\n",
       "    --link-color: #008dc0;\n",
       "    --link-color-pale: #97e1fb;\n",
       "    --link-hover: #00688e;\n",
       "}\n",
       "\n",
       "p.dataframe_description {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "table.dataframe {\n",
       "    font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n",
       "    font-size: 12px;\n",
       "    background-color: var(--background);\n",
       "    color: var(--text-color-dark);\n",
       "    border: none;\n",
       "    border-collapse: collapse;\n",
       "}\n",
       "\n",
       "table.dataframe th, td {\n",
       "    padding: 6px;\n",
       "    border: 1px solid transparent;\n",
       "    text-align: left;\n",
       "}\n",
       "\n",
       "table.dataframe th {\n",
       "    background-color: var(--background);\n",
       "    color: var(--header-text-color);\n",
       "}\n",
       "\n",
       "table.dataframe td {\n",
       "    vertical-align: top;\n",
       "}\n",
       "\n",
       "table.dataframe th.bottomBorder {\n",
       "    border-bottom-color: var(--bold-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:nth-child(odd) {\n",
       "    background: var(--background-odd);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:nth-child(even) {\n",
       "    background: var(--background);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:hover {\n",
       "    background: var(--background-hover);\n",
       "}\n",
       "\n",
       "table.dataframe a {\n",
       "    cursor: pointer;\n",
       "    color: var(--link-color);\n",
       "    text-decoration: none;\n",
       "}\n",
       "\n",
       "table.dataframe tr:hover > td a {\n",
       "    color: var(--link-color-pale);\n",
       "}\n",
       "\n",
       "table.dataframe a:hover {\n",
       "    color: var(--link-hover);\n",
       "    text-decoration: underline;\n",
       "}\n",
       "\n",
       "table.dataframe img {\n",
       "    max-width: fit-content;\n",
       "}\n",
       "\n",
       "table.dataframe th.complex {\n",
       "    background-color: var(--background);\n",
       "    border: 1px solid var(--background);\n",
       "}\n",
       "\n",
       "table.dataframe .leftBorder {\n",
       "    border-left-color: var(--inner-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe .rightBorder {\n",
       "    border-right-color: var(--inner-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe .rightAlign {\n",
       "    text-align: right;\n",
       "}\n",
       "\n",
       "table.dataframe .expanderSvg {\n",
       "    width: 8px;\n",
       "    height: 8px;\n",
       "    margin-right: 3px;\n",
       "}\n",
       "\n",
       "table.dataframe .expander {\n",
       "    display: flex;\n",
       "    align-items: center;\n",
       "}\n",
       "\n",
       "/* formatting */\n",
       "\n",
       "table.dataframe .null {\n",
       "    color: var(--text-color-pale);\n",
       "}\n",
       "\n",
       "table.dataframe .structural {\n",
       "    color: var(--text-color-medium);\n",
       "    font-weight: bold;\n",
       "}\n",
       "\n",
       "table.dataframe .dataFrameCaption {\n",
       "    font-weight: bold;\n",
       "}\n",
       "\n",
       "table.dataframe .numbers {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "table.dataframe td:hover .formatted .structural, .null {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "table.dataframe tr:hover .formatted .structural, .null {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "\n",
       "                </style>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%useLatestDescriptors\n",
    "%use lets-plot\n",
    "%use dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "29f403c2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Lets-Plot Kotlin API v.4.4.1. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.3.2.0."
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "LetsPlot.getInfo()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4ba77173",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/kotlindataframe+json": "{\"nrow\":5,\"ncol\":12,\"columns\":[\"untitled\",\"manufacturer\",\"model\",\"displ\",\"year\",\"cyl\",\"trans\",\"drv\",\"cty\",\"hwy\",\"fl\",\"class\"],\"kotlin_dataframe\":[{\"untitled\":1,\"manufacturer\":\"audi\",\"model\":\"a4\",\"displ\":1.8,\"year\":1999,\"cyl\":4,\"trans\":\"auto(l5)\",\"drv\":\"f\",\"cty\":18,\"hwy\":29,\"fl\":\"p\",\"class\":\"compact\"},{\"untitled\":2,\"manufacturer\":\"audi\",\"model\":\"a4\",\"displ\":1.8,\"year\":1999,\"cyl\":4,\"trans\":\"manual(m5)\",\"drv\":\"f\",\"cty\":21,\"hwy\":29,\"fl\":\"p\",\"class\":\"compact\"},{\"untitled\":3,\"manufacturer\":\"audi\",\"model\":\"a4\",\"displ\":2.0,\"year\":2008,\"cyl\":4,\"trans\":\"manual(m6)\",\"drv\":\"f\",\"cty\":20,\"hwy\":31,\"fl\":\"p\",\"class\":\"compact\"},{\"untitled\":4,\"manufacturer\":\"audi\",\"model\":\"a4\",\"displ\":2.0,\"year\":2008,\"cyl\":4,\"trans\":\"auto(av)\",\"drv\":\"f\",\"cty\":21,\"hwy\":30,\"fl\":\"p\",\"class\":\"compact\"},{\"untitled\":5,\"manufacturer\":\"audi\",\"model\":\"a4\",\"displ\":2.8,\"year\":1999,\"cyl\":6,\"trans\":\"auto(l5)\",\"drv\":\"f\",\"cty\":16,\"hwy\":26,\"fl\":\"p\",\"class\":\"compact\"}]}",
      "text/html": [
       "        <html>\n",
       "        <head>\n",
       "            <style type=\"text/css\">\n",
       "                :root {\n",
       "    --background: #fff;\n",
       "    --background-odd: #f5f5f5;\n",
       "    --background-hover: #d9edfd;\n",
       "    --header-text-color: #474747;\n",
       "    --text-color: #848484;\n",
       "    --text-color-dark: #000;\n",
       "    --text-color-medium: #737373;\n",
       "    --text-color-pale: #b3b3b3;\n",
       "    --inner-border-color: #aaa;\n",
       "    --bold-border-color: #000;\n",
       "    --link-color: #296eaa;\n",
       "    --link-color-pale: #296eaa;\n",
       "    --link-hover: #1a466c;\n",
       "}\n",
       "\n",
       ":root[theme=\"dark\"], :root [data-jp-theme-light=\"false\"], .dataframe_dark{\n",
       "    --background: #303030;\n",
       "    --background-odd: #3c3c3c;\n",
       "    --background-hover: #464646;\n",
       "    --header-text-color: #dddddd;\n",
       "    --text-color: #b3b3b3;\n",
       "    --text-color-dark: #dddddd;\n",
       "    --text-color-medium: #b2b2b2;\n",
       "    --text-color-pale: #737373;\n",
       "    --inner-border-color: #707070;\n",
       "    --bold-border-color: #777777;\n",
       "    --link-color: #008dc0;\n",
       "    --link-color-pale: #97e1fb;\n",
       "    --link-hover: #00688e;\n",
       "}\n",
       "\n",
       "p.dataframe_description {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "table.dataframe {\n",
       "    font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n",
       "    font-size: 12px;\n",
       "    background-color: var(--background);\n",
       "    color: var(--text-color-dark);\n",
       "    border: none;\n",
       "    border-collapse: collapse;\n",
       "}\n",
       "\n",
       "table.dataframe th, td {\n",
       "    padding: 6px;\n",
       "    border: 1px solid transparent;\n",
       "    text-align: left;\n",
       "}\n",
       "\n",
       "table.dataframe th {\n",
       "    background-color: var(--background);\n",
       "    color: var(--header-text-color);\n",
       "}\n",
       "\n",
       "table.dataframe td {\n",
       "    vertical-align: top;\n",
       "}\n",
       "\n",
       "table.dataframe th.bottomBorder {\n",
       "    border-bottom-color: var(--bold-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:nth-child(odd) {\n",
       "    background: var(--background-odd);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:nth-child(even) {\n",
       "    background: var(--background);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:hover {\n",
       "    background: var(--background-hover);\n",
       "}\n",
       "\n",
       "table.dataframe a {\n",
       "    cursor: pointer;\n",
       "    color: var(--link-color);\n",
       "    text-decoration: none;\n",
       "}\n",
       "\n",
       "table.dataframe tr:hover > td a {\n",
       "    color: var(--link-color-pale);\n",
       "}\n",
       "\n",
       "table.dataframe a:hover {\n",
       "    color: var(--link-hover);\n",
       "    text-decoration: underline;\n",
       "}\n",
       "\n",
       "table.dataframe img {\n",
       "    max-width: fit-content;\n",
       "}\n",
       "\n",
       "table.dataframe th.complex {\n",
       "    background-color: var(--background);\n",
       "    border: 1px solid var(--background);\n",
       "}\n",
       "\n",
       "table.dataframe .leftBorder {\n",
       "    border-left-color: var(--inner-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe .rightBorder {\n",
       "    border-right-color: var(--inner-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe .rightAlign {\n",
       "    text-align: right;\n",
       "}\n",
       "\n",
       "table.dataframe .expanderSvg {\n",
       "    width: 8px;\n",
       "    height: 8px;\n",
       "    margin-right: 3px;\n",
       "}\n",
       "\n",
       "table.dataframe .expander {\n",
       "    display: flex;\n",
       "    align-items: center;\n",
       "}\n",
       "\n",
       "/* formatting */\n",
       "\n",
       "table.dataframe .null {\n",
       "    color: var(--text-color-pale);\n",
       "}\n",
       "\n",
       "table.dataframe .structural {\n",
       "    color: var(--text-color-medium);\n",
       "    font-weight: bold;\n",
       "}\n",
       "\n",
       "table.dataframe .dataFrameCaption {\n",
       "    font-weight: bold;\n",
       "}\n",
       "\n",
       "table.dataframe .numbers {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "table.dataframe td:hover .formatted .structural, .null {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "table.dataframe tr:hover .formatted .structural, .null {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "            </style>\n",
       "        </head>\n",
       "        <body>\n",
       "            \n",
       "<table class=\"dataframe\" id=\"df_1644167168\"></table>\n",
       "\n",
       "<p class=\"dataframe_description\">DataFrame: rowsCount = 5, columnsCount = 12</p>\n",
       "        </body>\n",
       "        <script>\n",
       "            \n",
       "/*<!--*/\n",
       "call_DataFrame(function() { DataFrame.addTable({ cols: [{ name: \"<span title=\\\"untitled: Int\\\">untitled</span>\", children: [], rightAlign: true, values: [\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">1</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">2</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">3</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">4</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">5</span></span>\"] }, \n",
       "{ name: \"<span title=\\\"manufacturer: String\\\">manufacturer</span>\", children: [], rightAlign: false, values: [\"audi\",\"audi\",\"audi\",\"audi\",\"audi\"] }, \n",
       "{ name: \"<span title=\\\"model: String\\\">model</span>\", children: [], rightAlign: false, values: [\"a4\",\"a4\",\"a4\",\"a4\",\"a4\"] }, \n",
       "{ name: \"<span title=\\\"displ: Double\\\">displ</span>\", children: [], rightAlign: true, values: [\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">1,8</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">1,8</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">2,0</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">2,0</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">2,8</span></span>\"] }, \n",
       "{ name: \"<span title=\\\"year: Int\\\">year</span>\", children: [], rightAlign: true, values: [\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">1999</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">1999</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">2008</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">2008</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">1999</span></span>\"] }, \n",
       "{ name: \"<span title=\\\"cyl: Int\\\">cyl</span>\", children: [], rightAlign: true, values: [\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">4</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">4</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">4</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">4</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">6</span></span>\"] }, \n",
       "{ name: \"<span title=\\\"trans: String\\\">trans</span>\", children: [], rightAlign: false, values: [\"auto(l5)\",\"manual(m5)\",\"manual(m6)\",\"auto(av)\",\"auto(l5)\"] }, \n",
       "{ name: \"<span title=\\\"drv: String\\\">drv</span>\", children: [], rightAlign: false, values: [\"f\",\"f\",\"f\",\"f\",\"f\"] }, \n",
       "{ name: \"<span title=\\\"cty: Int\\\">cty</span>\", children: [], rightAlign: true, values: [\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">18</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">21</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">20</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">21</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">16</span></span>\"] }, \n",
       "{ name: \"<span title=\\\"hwy: Int\\\">hwy</span>\", children: [], rightAlign: true, values: [\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">29</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">29</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">31</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">30</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">26</span></span>\"] }, \n",
       "{ name: \"<span title=\\\"fl: String\\\">fl</span>\", children: [], rightAlign: false, values: [\"p\",\"p\",\"p\",\"p\",\"p\"] }, \n",
       "{ name: \"<span title=\\\"class: String\\\">class</span>\", children: [], rightAlign: false, values: [\"compact\",\"compact\",\"compact\",\"compact\",\"compact\"] }, \n",
       "], id: 1644167168, rootId: 1644167168, totalRows: 5 } ) });\n",
       "/*-->*/\n",
       "\n",
       "call_DataFrame(function() { DataFrame.renderTable(1644167168) });\n",
       "\n",
       "\n",
       "        </script>\n",
       "        </html>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "var mpgDf = DataFrame.readCSV(\"https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/data/mpg.csv\")\n",
    "mpgDf.head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c7adedff",
   "metadata": {},
   "outputs": [],
   "source": [
    "val mpgData = mpgDf.toMap()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e60fa1da",
   "metadata": {},
   "outputs": [],
   "source": [
    "val blankTheme = theme(line = elementBlank(), axisText=elementBlank(), axisTitle=elementBlank())\n",
    "                    .legendPositionNone()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f69504ac",
   "metadata": {},
   "source": [
    "## 1.Default presentation\n",
    "\n",
    "By default, `geomPie()` doesn't display any annotations and is not very informative."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "2518320d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"jRUCzn\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"hole\":0.2,\n",
       "\"mapping\":{\n",
       "\"fill\":\"class\"\n",
       "},\n",
       "\"stat\":\"count2d\",\n",
       "\"size\":22.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"data\":{\n",
       "\"..count..\":[47.0,41.0,62.0,5.0,11.0,33.0,35.0],\n",
       "\"..x..\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0],\n",
       "\"..y..\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0],\n",
       "\"class\":[\"compact\",\"midsize\",\"suv\",\"2seater\",\"minivan\",\"pickup\",\"subcompact\"]\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"jRUCzn\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "letsPlot(mpgData) + geomPie(size = 22, hole = 0.2) { fill = \"class\" }"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "84a01ef7",
   "metadata": {},
   "source": [
    "## 2. Change default annotation\n",
    "\n",
    "Add simple annotations. \n",
    "Аnnotations are placed inside sectors. If they do not fit, then external labels will appear."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ade97b5d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"PzpDvF\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"Dark2\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"hole\":0.2,\n",
       "\"mapping\":{\n",
       "\"fill\":\"class\"\n",
       "},\n",
       "\"stat\":\"count2d\",\n",
       "\"size\":22.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"tooltips\":\"none\",\n",
       "\"labels\":{\n",
       "\"lines\":[\"@class\"]\n",
       "},\n",
       "\"data\":{\n",
       "\"..count..\":[47.0,41.0,62.0,5.0,11.0,33.0,35.0],\n",
       "\"..x..\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0],\n",
       "\"..y..\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0],\n",
       "\"class\":[\"compact\",\"midsize\",\"suv\",\"2seater\",\"minivan\",\"pickup\",\"subcompact\"]\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"axis_title\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"axis_text\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"line\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"legend_position\":\"none\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"PzpDvF\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "letsPlot(mpgData) +\n",
    "    geomPie(\n",
    "        size = 22, hole = 0.2,\n",
    "        labels = layerLabels().line(\"@class\"),\n",
    "        tooltips = tooltipsNone\n",
    "    ) { fill = \"class\" } + \n",
    "    blankTheme + \n",
    "    scaleFillBrewer(palette = \"Dark2\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "edfdadaa",
   "metadata": {},
   "source": [
    "Add multiline annotations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "9c3226a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"AKaq4Y\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"Dark2\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"hole\":0.2,\n",
       "\"mapping\":{\n",
       "\"fill\":\"class\"\n",
       "},\n",
       "\"stat\":\"count2d\",\n",
       "\"size\":22.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"tooltips\":\"none\",\n",
       "\"labels\":{\n",
       "\"lines\":[\"@class\",\"(@{..prop..})\"],\n",
       "\"formats\":[{\n",
       "\"field\":\"..prop..\",\n",
       "\"format\":\".0%\"\n",
       "}]\n",
       "},\n",
       "\"data\":{\n",
       "\"..count..\":[47.0,41.0,62.0,5.0,11.0,33.0,35.0],\n",
       "\"..x..\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0],\n",
       "\"..y..\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0],\n",
       "\"..prop..\":[0.20085470085470086,0.1752136752136752,0.26495726495726496,0.021367521367521368,0.04700854700854701,0.14102564102564102,0.14957264957264957],\n",
       "\"class\":[\"compact\",\"midsize\",\"suv\",\"2seater\",\"minivan\",\"pickup\",\"subcompact\"]\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"axis_title\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"axis_text\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"line\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"legend_position\":\"none\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"AKaq4Y\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "letsPlot(mpgData) +\n",
    "    geomPie(\n",
    "        size = 22, hole = 0.2,\n",
    "        labels = layerLabels()\n",
    "                    .line(\"@class\")\n",
    "                    .line(\"(@{..prop..})\")\n",
    "                    .format(\"..prop..\", \".0%\"),\n",
    "        tooltips = tooltipsNone\n",
    "    ) { fill = \"class\" } + \n",
    "    blankTheme + \n",
    "    scaleFillBrewer(palette = \"Dark2\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d635c3eb",
   "metadata": {},
   "source": [
    "You can change labels size with `size()` function."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "06cc92f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"FObijn\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"Dark2\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"hole\":0.2,\n",
       "\"mapping\":{\n",
       "\"fill\":\"@as_discrete@class\"\n",
       "},\n",
       "\"stat\":\"count2d\",\n",
       "\"size\":22.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"data_meta\":{\n",
       "\"mapping_annotations\":[{\n",
       "\"aes\":\"fill\",\n",
       "\"annotation\":\"as_discrete\",\n",
       "\"parameters\":{\n",
       "\"label\":\"class\",\n",
       "\"order_by\":\"..count..\"\n",
       "}\n",
       "}]\n",
       "},\n",
       "\"tooltips\":\"none\",\n",
       "\"labels\":{\n",
       "\"lines\":[\"@..proppct.. %\"],\n",
       "\"annotation_size\":18,\n",
       "\"formats\":[{\n",
       "\"field\":\"..proppct..\",\n",
       "\"format\":\".1f\"\n",
       "}]\n",
       "},\n",
       "\"data\":{\n",
       "\"..proppct..\":[26.495726495726494,20.085470085470085,17.521367521367523,14.957264957264957,14.102564102564102,4.700854700854701,2.1367521367521367],\n",
       "\"..count..\":[62.0,47.0,41.0,35.0,33.0,11.0,5.0],\n",
       "\"..x..\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0],\n",
       "\"..y..\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0],\n",
       "\"@as_discrete@class\":[\"suv\",\"compact\",\"midsize\",\"subcompact\",\"pickup\",\"minivan\",\"2seater\"]\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"axis_title\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"axis_text\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"line\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"legend_position\":\"none\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"FObijn\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "letsPlot(mpgData) +\n",
    "    geomPie(\n",
    "        size = 22, hole = 0.2,\n",
    "        labels = layerLabels()\n",
    "                    .line(\"@..proppct.. %\")\n",
    "                    .format(\"..proppct..\", \".1f\")    \n",
    "                    .size(18),\n",
    "        tooltips = tooltipsNone\n",
    "    ) { fill = asDiscrete(\"class\", orderBy = \"..count..\") } + \n",
    "    blankTheme + \n",
    "    scaleFillBrewer(palette = \"Dark2\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "09d5f2d9",
   "metadata": {},
   "source": [
    "For more complex settings, you can use theme text settings like `size`, `color`, `bold`, `italic`. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "046a55c0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"9AT2PX\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"hole\":0.3,\n",
       "\"mapping\":{\n",
       "\"fill\":\"@as_discrete@class\"\n",
       "},\n",
       "\"stat\":\"count2d\",\n",
       "\"size\":20.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"data_meta\":{\n",
       "\"mapping_annotations\":[{\n",
       "\"aes\":\"fill\",\n",
       "\"annotation\":\"as_discrete\",\n",
       "\"parameters\":{\n",
       "\"label\":\"class\",\n",
       "\"order_by\":\"..count..\",\n",
       "\"order\":1\n",
       "}\n",
       "}]\n",
       "},\n",
       "\"tooltips\":\"none\",\n",
       "\"labels\":{\n",
       "\"lines\":[\"@..proppct.. %\"],\n",
       "\"formats\":[{\n",
       "\"field\":\"..proppct..\",\n",
       "\"format\":\".1f\"\n",
       "}]\n",
       "},\n",
       "\"data\":{\n",
       "\"..proppct..\":[2.1367521367521367,4.700854700854701,14.102564102564102,14.957264957264957,17.521367521367523,20.085470085470085,26.495726495726494],\n",
       "\"..count..\":[5.0,11.0,33.0,35.0,41.0,47.0,62.0],\n",
       "\"..x..\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0],\n",
       "\"..y..\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0],\n",
       "\"@as_discrete@class\":[\"2seater\",\"minivan\",\"pickup\",\"subcompact\",\"midsize\",\"compact\",\"suv\"]\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"axis_title\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"axis_text\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"line\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"legend_position\":\"right\",\n",
       "\"text\":{\n",
       "\"color\":\"#542788\",\n",
       "\"face\":\"bold italic\",\n",
       "\"size\":16.0,\n",
       "\"blank\":false\n",
       "}\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"9AT2PX\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "letsPlot(mpgData) +\n",
    "    geomPie(\n",
    "        size = 20, hole = 0.3,\n",
    "        labels = layerLabels()\n",
    "                    .line(\"@..proppct.. %\")\n",
    "                    .format(\"..proppct..\", \".1f\"),\n",
    "        tooltips = tooltipsNone\n",
    "    ) { fill = asDiscrete(\"class\", orderBy = \"..count..\", order = 1) } +\n",
    "    blankTheme +\n",
    "    theme(text = elementText(face = \"bold italic\", size = 16, color = \"#542788\")).legendPositionRight()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3dc5a688",
   "metadata": {},
   "source": [
    "## 3. Use colors of the flavor scheme\n",
    "\n",
    "You can combine Pie-Chart with different flavor schemes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "12b96312",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"6lemfC\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"Dark2\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"hole\":0.2,\n",
       "\"mapping\":{\n",
       "\"fill\":\"@as_discrete@class\"\n",
       "},\n",
       "\"stat\":\"count2d\",\n",
       "\"size\":20.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"data_meta\":{\n",
       "\"mapping_annotations\":[{\n",
       "\"aes\":\"fill\",\n",
       "\"annotation\":\"as_discrete\",\n",
       "\"parameters\":{\n",
       "\"label\":\"class\",\n",
       "\"order_by\":\"..count..\"\n",
       "}\n",
       "}]\n",
       "},\n",
       "\"tooltips\":\"none\",\n",
       "\"labels\":{\n",
       "\"lines\":[\"@..proppct.. %\"],\n",
       "\"annotation_size\":18,\n",
       "\"formats\":[{\n",
       "\"field\":\"..proppct..\",\n",
       "\"format\":\".1f\"\n",
       "}]\n",
       "},\n",
       "\"data\":{\n",
       "\"..proppct..\":[26.495726495726494,20.085470085470085,17.521367521367523,14.957264957264957,14.102564102564102,4.700854700854701,2.1367521367521367],\n",
       "\"..count..\":[62.0,47.0,41.0,35.0,33.0,11.0,5.0],\n",
       "\"..x..\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0],\n",
       "\"..y..\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0],\n",
       "\"@as_discrete@class\":[\"suv\",\"compact\",\"midsize\",\"subcompact\",\"pickup\",\"minivan\",\"2seater\"]\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"axis_title\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"axis_text\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"line\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"legend_position\":\"none\",\n",
       "\"flavor\":\"darcula\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"6lemfC\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "letsPlot(mpgData) + \n",
    "    geomPie(\n",
    "        size = 20, hole = 0.2,\n",
    "        labels = layerLabels()\n",
    "                    .line(\"@..proppct.. %\")\n",
    "                    .format(\"..proppct..\", \".1f\")\n",
    "                    .size(18),\n",
    "        tooltips = tooltipsNone\n",
    "    ) { fill = asDiscrete(\"class\", orderBy = \"..count..\") } +\n",
    "    blankTheme + \n",
    "    scaleFillBrewer(palette = \"Dark2\") +\n",
    "    flavorDarcula()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a11f1e03",
   "metadata": {},
   "source": [
    "## 4. Annotations for Pie-Chart with explode parameter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "73bc9c1c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"nhJHv7\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "\"explode\":[0.0,0.0,0.0,0.1,0.1,0.2,0.3,0.4,0.6],\n",
       "\"name\":[\"20-50 km\",\"50-75 km\",\"10-20 km\",\"75-100 km\",\"3-5 km\",\"7-10 km\",\"5-7 km\",\">100 km\",\"2-3 km\"],\n",
       "\"count\":[1109.0,696.0,353.0,192.0,168.0,86.0,74.0,65.0,53.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"scale_mapper_kind\":\"color_gradient\",\n",
       "\"high\":\"light_green\",\n",
       "\"low\":\"dark_blue\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"hole\":0.3,\n",
       "\"mapping\":{\n",
       "\"slice\":\"count\",\n",
       "\"explode\":\"explode\",\n",
       "\"fill\":\"name\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":20.0,\n",
       "\"stroke_color\":\"black\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"stroke\":1.0,\n",
       "\"labels\":{\n",
       "\"variables\":[\"name\",\"count\"]\n",
       "},\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"axis_title\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"axis_text\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"line\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"legend_position\":\"none\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"nhJHv7\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val length = mapOf(\n",
    "  \"name\" to listOf(\"20-50 km\", \"50-75 km\", \"10-20 km\", \"75-100 km\", \"3-5 km\", \"7-10 km\", \"5-7 km\", \">100 km\", \"2-3 km\"),\n",
    "  \"count\" to listOf(1109, 696, 353, 192, 168, 86, 74, 65, 53),\n",
    "  \"explode\" to listOf(0, 0, 0, 0.1, 0.1, 0.2, 0.3, 0.4, 0.6)\n",
    ")\n",
    "\n",
    "letsPlot(length) +\n",
    "    geomPie(\n",
    "        stat = Stat.identity, stroke = 1, strokeColor = \"black\", size = 20, hole = 0.3,\n",
    "        labels = layerLabels(\"name\", \"count\")\n",
    "    ) { fill = \"name\"; slice = \"count\"; explode = \"explode\" } + \n",
    "    scaleFillGradient(low = \"dark_blue\", high = \"light_green\") +\n",
    "    blankTheme\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "efcaa434",
   "metadata": {},
   "source": [
    "## 5. Annotations on scatter pie plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "81120702",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"wPEPe5\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "\"s\":[3.0,1.0,2.0,1.0,4.0,1.0,3.0,3.0,2.0,1.0],\n",
       "\"x\":[1.0,1.0,1.0,1.0,1.0,1.5,1.5,2.0,2.0,2.0],\n",
       "\"y\":[1.0,1.0,1.0,1.0,1.0,2.0,2.0,1.5,1.5,1.5]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"limits\":[0.5,2.5]\n",
       "},{\n",
       "\"aesthetic\":\"y\",\n",
       "\"limits\":[0.5,2.5]\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"slice\":\"s\",\n",
       "\"fill\":\"@as_discrete@s\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"data_meta\":{\n",
       "\"mapping_annotations\":[{\n",
       "\"aes\":\"fill\",\n",
       "\"annotation\":\"as_discrete\",\n",
       "\"parameters\":{\n",
       "\"label\":\"s\"\n",
       "}\n",
       "}]\n",
       "},\n",
       "\"tooltips\":\"none\",\n",
       "\"labels\":{\n",
       "\"variables\":[\"s\"],\n",
       "\"annotation_size\":16\n",
       "},\n",
       "\"data\":{\n",
       "\"@as_discrete@s\":[3.0,1.0,2.0,1.0,4.0,1.0,3.0,3.0,2.0,1.0]\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"wPEPe5\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "letsPlot(\n",
    "    data = mapOf(\n",
    "        \"x\" to listOf(1, 1, 1, 1, 1, 1.5, 1.5, 2, 2, 2),\n",
    "        \"y\" to listOf(1, 1, 1, 1, 1, 2, 2, 1.5, 1.5, 1.5),\n",
    "        \"s\" to listOf(3, 1, 2, 1, 4, 1, 3, 3, 2, 1)\n",
    "    )\n",
    ") + \n",
    "    xlim(0.5 to 2.5) + ylim(0.5 to 2.5) +\n",
    "    geomPie(stat = Stat.identity, labels = layerLabels(\"s\").size(16), tooltips = tooltipsNone) {\n",
    "        x = \"x\"; y = \"y\"; slice = \"s\"; fill = asDiscrete(\"s\")\n",
    "    }"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a0aea53",
   "metadata": {},
   "source": [
    "## 6. Annotations for Pie-Chart with different sector's size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "783f37e9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"CwixMU\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "\"s\":[1.0,2.0,3.0],\n",
       "\"n\":[\"a\",\"b\",\"c\"]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"slice\":\"s\",\n",
       "\"size\":\"n\",\n",
       "\"fill\":\"n\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"labels\":{\n",
       "\"lines\":[\"^fill (^slice)\"]\n",
       "},\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"axis_title\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"axis_text\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"line\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"legend_position\":\"right\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"CwixMU\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "letsPlot(data = mapOf(\"n\" to listOf(\"a\", \"b\", \"c\"), \"s\" to listOf(1, 2, 3))) + \n",
    "    blankTheme +\n",
    "    geomPie(stat = Stat.identity, labels = layerLabels().line(\"^fill (^slice)\")) {\n",
    "        fill = \"n\"; slice = \"s\"; size = \"n\"\n",
    "    } + \n",
    "    theme().legendPositionRight()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Kotlin",
   "language": "kotlin",
   "name": "kotlin"
  },
  "language_info": {
   "codemirror_mode": "text/x-kotlin",
   "file_extension": ".kt",
   "mimetype": "text/x-kotlin",
   "name": "kotlin",
   "nbconvert_exporter": "",
   "pygments_lexer": "kotlin",
   "version": "1.8.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
